ruby:
  index ||= false

  if index
    require_locals(['assoc'], local_assigns)
  else
    require_locals(['assoc', 'parent_item'], local_assigns)
  end

  # optional locals
  assoc_name          ||= assoc.to_s                      # 'restaurant_bars'
  title               ||= assoc_name.titleize             # 'Restaurant Bars'
  add_button_text     ||= t('fae.common.add', title: title.singularize)
  hide_add_button     ||= false
  hide_delete_button  ||= false
  ordered             ||= false
  has_thumb           ||= false
  edit_column         ||= false
  cols                ||= []
  helper_text         ||= ''

  # lesser known optional locals, dervived from options by default
  assoc_name_singular ||= assoc_name.singularize          # 'restaurant_bar'
  new_path            ||= "new_#{fae_path}_#{assoc_name_singular}_path"
  edit_path           ||= "edit_#{fae_path}_#{assoc_name_singular}_path"

  begin
    if index
      new_path = self.send(new_path)
    else
      new_path = self.send(new_path, item_id: parent_item.id, item_class: parent_item.class.to_s)
    end
  rescue
    new_path += new_path['?'] ? '&' : '?'
    new_path += "item_id=#{parent_item.id}&=item_class=#{parent_item.class.to_s}"
  end

  options_for_table = { index: index, assoc: assoc, assoc_name: assoc_name, title: title, add_button_text: add_button_text, hide_add_button: hide_add_button, hide_delete_button: hide_delete_button, ordered: ordered, has_thumb: has_thumb, edit_column: edit_column, cols: cols, assoc_name_singular: assoc_name_singular, new_path: new_path, edit_path: edit_path }
  options_for_table[:parent_item] = parent_item unless index

section.addedit-form.js-addedit-form class="#{'content' if index}"
  - if index
    == render 'fae/shared/shared_nested_table', options_for_table

  - else
    - unless hide_add_button
      a.js-add-link.table-add-link.button.-small href=new_path = add_button_text
    h2 = title
    - if helper_text.present?
      h6.table-helper-text = helper_text
    == render 'fae/application/flash_messages'
    == render 'fae/shared/shared_nested_table', options_for_table
